import { CompatibilityTree } from '../compatibility-tree'
import { DependencyAnalyzer } from './dependency-analyzer/service'
import { EnvironmentSimulator } from './environment-simulator/service'
import { DiagnosticEngine } from './diagnostic-engine/service'

/**
 * AI集成模块主入口
 * 提供统一的AI功能访问接口
 */
export class AIIntegration {
  readonly dependencyAnalyzer: DependencyAnalyzer
  readonly environmentSimulator: EnvironmentSimulator
  readonly diagnosticEngine: DiagnosticEngine

  constructor(tree: CompatibilityTree) {
    this.dependencyAnalyzer = new DependencyAnalyzer(tree)
    this.environmentSimulator = new EnvironmentSimulator()
    this.diagnosticEngine = new DiagnosticEngine()
  }

  /**
   * 执行完整的AI分析流程
   * @returns 综合分析报告
   */
  async runFullAnalysis(): Promise<AnalysisReport> {
    const [deps, tests, diagnostics] = await Promise.all([
      this.dependencyAnalyzer.detectConflicts(),
      this.environmentSimulator.runChaosTests('default', []),
      this.diagnosticEngine.analyzeError('')
    ])

    return {
      timestamp: new Date(),
      dependencyAnalysis: deps,
      environmentTests: tests,
      diagnostics
    }
  }
}

interface AnalysisReport {
  timestamp: Date
  dependencyAnalysis: any
  environmentTests: any
  diagnostics: any[]
}

// 便捷导出常用服务
export { DependencyAnalyzer, EnvironmentSimulator, DiagnosticEngine }